package com.ruoyi.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;

import com.ruoyi.web.domain.Post;
import com.ruoyi.web.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.mapper.ReportMapper;
import com.ruoyi.web.domain.Report;
import com.ruoyi.web.service.IReportService;

/**
 * 举报Service业务层处理
 *
 * @author jiwei
 * @date 2024-05-16
 */
@Service
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements IReportService {
    @Autowired
    private ReportMapper reportMapper;
    @Autowired
    IPostService postService;


    /**
     * 查询举报
     *
     * @param id 举报主键
     * @return 举报
     */
    @Override
    public Report selectReportById(Long id) {
        return reportMapper.selectReportById(id);
    }

    /**
     * 查询举报列表
     *
     * @param report 举报
     * @return 举报
     */
    @Override
    public List<Report> selectReportList(Report report) {
        return reportMapper.selectReportList(report);
    }

    /**
     * 新增举报
     *
     * @param report 举报
     * @return 结果
     */
    @Override
    public int insertReport(Report report) {
            return reportMapper.insertReport(report);
    }

    /**
     * 修改举报
     *
     * @param report 举报
     * @return 结果
     */
    @Override
    public int updateReport(Report report) {
        if (report.getStatus().equals(1L)){
            Post post = new Post();
            post.setId(report.getFromId());
            post.setStatus(1L);
            postService.updatePost(post);
        }
        return reportMapper.updateReport(report);
    }

    /**
     * 批量删除举报
     *
     * @param ids 需要删除的举报主键
     * @return 结果
     */
    @Override
    public int deleteReportByIds(Long[] ids) {
        return reportMapper.deleteReportByIds(ids);
    }

    /**
     * 删除举报信息
     *
     * @param id 举报主键
     * @return 结果
     */
    @Override
    public int deleteReportById(Long id) {
        return reportMapper.deleteReportById(id);
    }
}
